﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace QLTV.HeThongXuLy
{
    class QuyDinhDB
    {
        public static DataTable LayDanhSachQuyDinh()
        {
            string sql = "Select * from THAMSO";
            return ConnectDB.ExecQuery(sql);
        }
        public static bool TaoQuyDinh(QuyDinh quydinh)
        {
            try
            {
                string sql =
                    "INSERT INTO THAMSO VALUES ('" + quydinh.TuoiToiThieu + "',N'"
                    + quydinh.TuoiToiDa + "','"
                    + quydinh.ThoiHanSuDung + "','"
                    + quydinh.KhoangCachXuatBan + "','"
                    + quydinh.SoLuongSachMuonToiDa + "','"
                    + quydinh.ThoiGianMuonToiDa + "','"
                    + quydinh.TienPhatToiThieu + "')";

                ConnectDB.ExecNonQuery(sql);

                return true;
            }
            catch (Exception ex)
            {
               // MessageBox.Show(ex.Message + ":Error");
                return false;

            }

        }
        public static bool SuaQuyDinh(QuyDinh quydinh)
        {
            try
            {
                string sql =
                    "UPDATE THAMSO SET TuoiToiThieu='" + quydinh.TuoiToiThieu +
                    "', TuoiToiDa='" + quydinh.TuoiToiDa +
                    "', ThoiHanSuDung='" + quydinh.ThoiHanSuDung +
                    "', KhoangCachXuatBan='" + quydinh.KhoangCachXuatBan +
                    "', SoLuongSachMuonToiDa='" + quydinh.SoLuongSachMuonToiDa +
                    "',ThoiGianMuonToiDa='" + quydinh.ThoiGianMuonToiDa +
                    "', TienPhatToiThieu='" + quydinh.TienPhatToiThieu + "'";

                ConnectDB.ExecNonQuery(sql);

                return true;
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message + ":Error");
                return false;

            }

        }

    }
}
